﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace WcfService_Restful.DAO
{
    public class Phuong_DAO : DataProvider
    {
        public Phuong_DAO()
        {
            Connect();
        }

        public object ConvertDataTableToArray(DataTable dt, int i)
        {
            DTO.Phuong_DTO data = new DTO.Phuong_DTO();
            data.MaPhuong = Convert.ToInt32(dt.Rows[i]["MaPhuong"].ToString());
            data.TenPhuong = dt.Rows[i]["TenPhuong"].ToString();
            return (object)data;
        }

        public DTO.Phuong_DTO[] GetData()
        {
            try
            {
                String sql = "Select * From Phuong Order By TenPhuong Asc";
                DataTable dt = ExecuteQuery(sql);
                DTO.Phuong_DTO[] ds = new DTO.Phuong_DTO[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                    ds[i] = (DTO.Phuong_DTO)ConvertDataTableToArray(dt, i);
                Disconnect();
                return ds;
            }
            catch
            {
                Disconnect();
                return null;
            }
        }
    }
}